package com.danger.Fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.danger.Activity.MainActivity;
import com.danger.Activity.R;

/**
 * Created by 俊 on 2016/6/2.
 */
public class IndexFragment extends BaseFragment implements View.OnClickListener {

    private View view;
    private Button index_location_button;
    private Button index_search_button;
    private Toolbar toolbar;
    private MainActivity activity;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        view = inflater.inflate(R.layout.fragment_index, container, false);

        initView();
        initEvent();

        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        toolbar.setVisibility(View.VISIBLE);
        activity.setSupportActionBar(toolbar);
    }

    @Override
    public void onPause() {
        super.onPause();
        toolbar.setVisibility(View.VISIBLE);
        activity.setSupportActionBar(toolbar);
    }

    @Override
    public void onResume() {
        super.onResume();
        toolbar.setVisibility(View.VISIBLE);
        activity.setSupportActionBar(toolbar);
    }

    @Override
    public void initView() {
        activity = (MainActivity) getActivity();
        toolbar = activity.getToolbar();
        toolbar.setTitle("地图");
        toolbar.setTitleTextColor(Color.WHITE);
        activity.setSupportActionBar(toolbar);
        index_location_button = (Button) view.findViewById(R.id.index_location_button);
        index_search_button = (Button) view.findViewById(R.id.index_search_button);
    }

    @Override
    public void initEvent() {
        index_location_button.setOnClickListener(this);
        index_search_button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.index_location_button:
                getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new LocationFragment()).commit();
                break;
            case R.id.index_search_button:
                getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new SearchFragment()).commit();
                break;
            default:
                break;
        }
    }
}